<?php class Messages { 

    /***
     * DB Fields: id
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     **/
    var $id;

    /***
     * DB Fields: fromCharId
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     **/
    var $fromCharId;

    /***
     * DB Fields: toCharId
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     **/
    var $toCharId;

    /***
     * DB Fields: messageType
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     **/
    var $messageType;

    /***
     * DB Fields: subject
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     **/
    var $subject;

    /***
     * DB Fields: message
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     **/
    var $message;

    /***
     * DB Fields: dateTime
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     **/
    var $dateTime;

    /***
     * DB Fields: read
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     **/
    var $read;

//--------------- GET METHODS ----------------------------- //
    /***
     * Get value for field: id
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @result id
     **/
    function get_id( ) {
        // returns the value of id
        return $this->id;
    }


    /***
     * Get value for field: fromCharId
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @result fromCharId
     **/
    function get_fromCharId( ) {
        // returns the value of fromCharId
        return $this->fromCharId;
    }


    /***
     * Get value for field: toCharId
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @result toCharId
     **/
    function get_toCharId( ) {
        // returns the value of toCharId
        return $this->toCharId;
    }


    /***
     * Get value for field: messageType
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @result messageType
     **/
    function get_messageType( ) {
        // returns the value of messageType
        return $this->messageType;
    }


    /***
     * Get value for field: subject
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @result subject
     **/
    function get_subject( ) {
        // returns the value of subject
        return $this->subject;
    }


    /***
     * Get value for field: message
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @result message
     **/
    function get_message( ) {
        // returns the value of message
        return $this->message;
    }


    /***
     * Get value for field: dateTime
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @result dateTime
     **/
    function get_dateTime( ) {
        // returns the value of dateTime
        return $this->dateTime;
    }


    /***
     * Get value for field: read
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @result read
     **/
    function get_read( ) {
        // returns the value of read
        return $this->read;
    }


//--------------- SET METHODS ----------------------------- //
    /***
     * Set value for field: id
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param id
     * @result void
     **/
    function set_id( $id ) {
        // sets the value of id
        $this->id = $id;
    }

    /***
     * Set value for field: fromCharId
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param fromCharId
     * @result void
     **/
    function set_fromCharId( $fromCharId ) {
        // sets the value of fromCharId
        $this->fromCharId = $fromCharId;
    }

    /***
     * Set value for field: toCharId
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param toCharId
     * @result void
     **/
    function set_toCharId( $toCharId ) {
        // sets the value of toCharId
        $this->toCharId = $toCharId;
    }

    /***
     * Set value for field: messageType
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param messageType
     * @result void
     **/
    function set_messageType( $messageType ) {
        // sets the value of messageType
        $this->messageType = $messageType;
    }

    /***
     * Set value for field: subject
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param subject
     * @result void
     **/
    function set_subject( $subject ) {
        // sets the value of subject
        $this->subject = $subject;
    }

    /***
     * Set value for field: message
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param message
     * @result void
     **/
    function set_message( $message ) {
        // sets the value of message
        $this->message = $message;
    }

    /***
     * Set value for field: dateTime
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param dateTime
     * @result void
     **/
    function set_dateTime( $dateTime ) {
        // sets the value of dateTime
        $this->dateTime = $dateTime;
    }

    /***
     * Set value for field: read
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param read
     * @result void
     **/
    function set_read( $read ) {
        // sets the value of read
        $this->read = $read;
    }

//--------------- CRUD METHODS ----------------------------- //
    /***
     * Create a new Record: messages
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param id
     * @param fromCharId
     * @param toCharId
     * @param messageType
     * @param subject
     * @param message
     * @param dateTime
     * @param read
     * @result void
     **/
    function createnew_messages( $id, $fromCharId, $toCharId, $messageType, $subject, $message, $dateTime, $read ) {

        // items to be inserted in the database 
        $_obj = array($id,
                      $fromCharId,
                      $toCharId,
                      $messageType,
                      $subject,
                      $message,
                      $dateTime,
                      $read); 

        // database object connection
        $dbConn = $GLOBALS['dbConn'];

        // perform insert in the database
        $dbConn->insert("messages", $_obj);
    }

    /***
     * Retrived an existing record: messages
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param id
     * @result new Messages
     **/
    function get_messages( $id ) {

        // retrive the data
        $dbConn = $GLOBALS['dbConn'];

        // retrieved value in the database
        $_resultSet = $dbConn->doQuery("SELECT * FROM messages WHERE id = '$id'");

        $__messagesObj = new messages();
        // return the retrived from the database

        // create a new object
        $__obj = new Messages();
        $__obj->set_id($_resultSet[0]['id']);
        $__obj->set_fromCharId($_resultSet[0]['fromCharId']);
        $__obj->set_toCharId($_resultSet[0]['toCharId']);
        $__obj->set_messageType($_resultSet[0]['messageType']);
        $__obj->set_subject($_resultSet[0]['subject']);
        $__obj->set_message($_resultSet[0]['message']);
        $__obj->set_dateTime($_resultSet[0]['dateTime']);
        $__obj->set_read($_resultSet[0]['read']);


        return $__obj;
    }

    /***
     * Update an existing record: messages
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param id
     * @param itemsToBeUpdated = array()
     * @result void
     **/
    function update_messages( $id, $itemsToBeUpdated = array() ) {

         // get database connection
         $dbConn = $GLOBALS['dbConn'];

         // performs update in the database
         foreach($itemsToBeUpdated as $_fName => $_fVal) { 
               $dbConn->addValuePair($_fName, $_fVal);
         }

         // perform update operation
         $dbConn->update("messages", "id = '$id'");
    }

    /***
     * Delete an existing record: messages
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param id
     * @result void
     **/
    function delete_messages( $id ) {

         // get database connection
         $dbConn = $GLOBALS['dbConn'];

         // performs deletion of data
         $dbConn->delete("messages", "id = '$id'");
    }

    /***
     * Retrived list of objects base on a given parameters: messages
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param conditionalStatement = ''
     * @result collection of objects: Messages
     **/
    function list_messages( $conditionalStatement = '' ) {

         $dbConn = $GLOBALS['dbConn'];
         // check if there is a given parameter list
         if(!empty($conditionalStatement)) { 
              $sqlStatement = "SELECT * FROM messages WHERE $conditionalStatement"; 
         } else { 
              $sqlStatement = "SELECT * FROM messages";
         }

         // retrieve the values base on the query result
         $__resObj = $dbConn->doQuery($sqlStatement);

         $__collectionOfObjects = array();
         foreach($__resObj as $__rs) { 
            $__newObj = new Messages();

            $__newObj->set_id($__rs['id']);
            $__newObj->set_fromCharId($__rs['fromCharId']);
            $__newObj->set_toCharId($__rs['toCharId']);
            $__newObj->set_messageType($__rs['messageType']);
            $__newObj->set_subject($__rs['subject']);
            $__newObj->set_message($__rs['message']);
            $__newObj->set_dateTime($__rs['dateTime']);
            $__newObj->set_read($__rs['read']);

            // add object to collection 
            array_push($__collectionOfObjects, $__newObj);
         }

         // return collection of objects
         return $__collectionOfObjects;
    }

} ?>